package com.wyc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wyc.anno.Log;
import com.wyc.mapper.EmpsMapper;
import com.wyc.pojo.Emp;
import com.wyc.pojo.PageBean;
import com.wyc.pojo.Result;
import com.wyc.service.EmpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class EmpsServiceImpl implements EmpsService {
    @Autowired
    private EmpsMapper empsMapper;
    @Override
    public PageBean<Emp> page(Integer pageindex,Integer pagesize) {

        PageHelper.startPage(pageindex,pagesize);
        Page<Emp> p= (Page<Emp>) empsMapper.list();
        PageBean<Emp> empPageBean=new PageBean<>();
        empPageBean.setCount(p.getTotal());
        empPageBean.setRows(p.getResult());

        return empPageBean;
    }

    @Override
    public void delByIds(List<Integer> ids) {
        empsMapper.delByIds(ids);
    }

    @Override
    public void delByDeptId(Integer deptId) {
        empsMapper.delByDeptId(deptId);
    }

    @Log
    @Override
    public void save(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empsMapper.save(emp);
    }

    @Override
    public Emp getById(Integer id) {
        return empsMapper.getById(id);
    }

    @Log
    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empsMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empsMapper.selectByUsernameAndPwd(emp);
    }
}
